<?php

/**
 * This is the model class for table "user".
 *
 * The followings are the available columns in table 'user':
 * @property integer $idUser
 * @property string $Name
 * @property integer $ID_Number
 * @property string $UserName
 * @property string $Password
 * @property string $Email
 * @property double $Balance
 * @property string $Gender
 * @property string $Birthday
 * @property string $Phone
 *
 * The followings are the available model relations:
 * @property Auction[] $auctions
 * @property Bid[] $bs
 */
class User extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return User the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'User';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('idUser, Name, ID_Number, UserName, Password, Email, Gender, Phone', 'required'),
			array('idUser, ID_Number', 'numerical', 'integerOnly'=>true),
			array('Balance', 'numerical'),
			array('Name, UserName, Password, Email', 'length', 'max'=>45),
			array('Gender', 'length', 'max'=>1),
			array('Phone', 'length', 'max'=>20),
			array('Birthday', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('idUser, Name, ID_Number, UserName, Password, Email, Balance, Gender, Birthday, Phone', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'auctions' => array(self::HAS_MANY, 'Auction', 'idCurrent_user_bid'),
			'bs' => array(self::HAS_MANY, 'Bid', 'idUser'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'idUser' => 'Id User',
			'Name' => 'Name',
			'ID_Number' => 'Id Number',
			'UserName' => 'User Name',
			'Password' => 'Password',
			'Email' => 'Email',
			'Balance' => 'Balance',
			'Gender' => 'Gender',
			'Birthday' => 'Birthday',
			'Phone' => 'Phone',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('idUser',$this->idUser);
		$criteria->compare('Name',$this->Name,true);
		$criteria->compare('ID_Number',$this->ID_Number);
		$criteria->compare('UserName',$this->UserName,true);
		$criteria->compare('Password',$this->Password,true);
		$criteria->compare('Email',$this->Email,true);
		$criteria->compare('Balance',$this->Balance);
		$criteria->compare('Gender',$this->Gender,true);
		$criteria->compare('Birthday',$this->Birthday,true);
		$criteria->compare('Phone',$this->Phone,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}